var bol = 0;
var iptAct = document.querySelector('.ipt.act')
var selBox = document.querySelector('.box')
var selBoxItem = document.querySelectorAll('.box .item')

function handClickIpt() {
  iptAct.addEventListener('click', function () {
    var _this = this;
    if(bol == 0) {
      _this.style = "border-radius: 5px 5px 0 0;border-bottom: 0;"
      selBox.style.display = "block"
      bol = 1
    }else {
      _this.style = ""
      selBox.style.display = "none"
      bol = 0
    }
  });
}
handClickIpt()
for (var i = 0; i < selBoxItem.length; i++) {
  selBoxItem[i].addEventListener('click', function () {
    $("input[name='gongm']").val(this.innerText)
    iptAct.innerHTML = this.innerText + "<span></span>"
    iptAct.style = ""
    selBox.style.display = "none"
    bol = 0
  })
}

var lab = document.querySelectorAll('.label')
var labI = document.querySelectorAll('.label i')
for (var i = 0; i < lab.length; i++) {
  lab[i].index = i
  lab[i].addEventListener('click', function () {
    var _this = this;
    for (var j = 0; j < lab.length; j++) {
      lab[j].classList.remove('active')
      iptBoxMustIpt[4].value = labI[_this.index].innerHTML
    }
    this.classList.add('active')
  });
}



var iptBoxMust = document.querySelectorAll(".ipt-box.act")
var iptBoxMustIpt = document.querySelectorAll(".ipt-box.act input")
$(".btn-submit").click(function () {
  for (var i = 0;i<iptBoxMust.length;i++) {
    if (iptBoxMustIpt[i].value == "") {
      alert(iptBoxMustIpt[i].placeholder)
      iptBoxMustIpt[i].focus()
      return false
    } else if(iptBoxMustIpt[4].value=="") {
      iptBoxMustIpt[4].focus()
      alert('请输入捐款金额')
      return false
    }
  }
  console.log(($("form").serialize()))
})

